package top.kaoshanji.p2ch15b;

/**
 * 代码清单-p2ch15b-454页b：一个简单的消费者
 * author kaoshanji
 * ^_^
 * create time 2025/2/24 16:17
 */
public class MyBlockingQueueConsumer extends Thread {

    private MyBlockingQueue<String> queue;

    public MyBlockingQueueConsumer(MyBlockingQueue<String> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        try {
            while (true) {
                String task = queue.take();
                System.out.println("handle task " + task);
                Thread.sleep((int) (Math.random() * 100));
            }
        } catch (InterruptedException e) {
            /// ///
        }

    }
}
